package java19_1_16;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author yuisama
 * @date 2022/01/16 09:20
 **/
class Student {
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
    // 当前对象和传入的obj相比
    public boolean equals(Object obj) {
        // 1.判断obj是否为空
        if (obj == null) {
            return false;
        }
        // 2.判断obj是否就是自己
        if (obj == this) {
            return true;
        }
        // 3.判断obj是否是Student类的对象
        if (!(obj instanceof Student)) {
            return false;
        }
        // 4.obj一定是Student类的对象而且与当前对象不是一个地址
        // 向下转型还原为Student，比较当前对象的属性和传入对象的属性
        Student stu = (Student) obj;
        return this.name.equals(stu.name) && this.age == stu.age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

interface IMessage {
    void printMsg();
}
class MessageImpl implements IMessage {
    @Override
    public void printMsg() {
        System.out.println("科大的老铁们都回家了，工程大的还会远吗~~");
    }
}


public class ObjectTest {
    public static void main(String[] args) {
        // 数组引用
        int[] data = {1,2,3,4,5,6,7};
        // 接口引用
        IMessage msg = new MessageImpl();
        Object obj1 = data;
        Object obj2 = msg;
        int[] ret = (int[]) obj1;
        IMessage test = (IMessage) obj2;
        System.out.println(Arrays.toString(ret));
        test.printMsg();
    }
}